package cn.appsys.interceptor;

import cn.appsys.pojo.BackendUser;
import cn.appsys.pojo.User;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class sysInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        BackendUser backendUser = (BackendUser) session.getAttribute("userSession");
        User user = (User) session.getAttribute("devUserSession");
        String path = request.getRequestURI();
        if (path.indexOf("dologin") != -1 || path.indexOf("loginOut") != -1 || path.indexOf("toLogin") != -1 || path.indexOf("toMain") != -1 || path.indexOf("toChoose") != -1){
            return true;
        }else if (backendUser != null || user != null) {
            return true;
        }
        response.sendRedirect(request.getContextPath()+"/403.jsp");
        return false;
    }

}
